package com.exam.Controller;

import com.exam.Entity.ApiResult;
import com.exam.Service.QuestionService;
import com.exam.util.ApiResultHandler;
import com.exam.vo.AnswerVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collections;
import java.util.List;
import java.util.Map;


@RestController
public class QuestionController {

    @Autowired
    private QuestionService answerService;

    @GetMapping("/questions/{page}/{size}")
    public ApiResult findAllQuestion(@PathVariable("page") Integer page, @PathVariable("size") Integer size){
//       Page<AnswerVO> answerVOPage = new Page<>(page,size);
//       IPage<AnswerVO> answerVOIPage = answerService.findAll(answerVOPage);
//       return ApiResultHandler.buildApiResult(200,"查询所有题库",answerVOIPage);
        ApiResult apiResult;
        List<AnswerVO> res = answerService.findAll(page,size);
        List<AnswerVO> t = answerService.findTotal(page,size);
        // 构造返回数据
        Map<String, Object> data = new java.util.HashMap<>();
        data.put("records", res);               // 返回的试卷列表
        data.put("current", page);              // 当前页码
        data.put("size", size);                 // 每页大小
        data.put("total", t.size());          // 总记录数（列表长度）

        // 构建 ApiResult
        apiResult = ApiResultHandler.buildApiResult(200, "请求成功！", data);

        return apiResult;
    }

}
